package logic

import (
	"context"
	"smart-health-platforms/config"
	"user_srv/internal/dao"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateSessionLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSessionLogic {
	return &CreateSessionLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateSessionLogic) CreateSession(in *user.CreateSessionRequest) (*user.CreateSessionResponse, error) {
	userID := uint64(in.UserId)
	id, err := dao.NewChatSessionDao(config.DB).
		CreateSession(l.ctx, userID, in.Title)
	if err != nil {
		return nil, err
	}
	return &user.CreateSessionResponse{SessionId: id}, nil

}
